<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
include('application/libraries/eac_curl.class.php');
class Home extends MX_Controller {

	function __construct(){
		parent::__construct();
		$this->template->write('title','');
		$this->template->write('meta_keywords','');
		$this->template->write('meta_description','');
		$this->template->write('meta_image','');
		$this->template->write('meta_video','');
	}
	
	/*-------------------------------------- FrontEnd --------------------------------------*/
	function index(){
		set_time_limit(5000);
		$options = array();
		$options['CURLOPT_AUTOREFERER']    = 1;
		$options['CURLOPT_CRLF']           = 1;
		$options['CURLOPT_NOPROGRESS']     = 1;
		$http = new cURL($options);
		$http->setOptions($options);

		for($i==1; $i<=13; $i++){
			$src = $http->get('http://www.gamevui.com/game-viet/games?p='.$i);
			preg_match_all('/<li itemid="(.*?)" class="(.*?)"><a href="(.*?)"(.*?)title="(.*?)">(.*?)<img data-original="(.*?)" alt="(.*?)" src="(.*?)" class="lazy"\/>(.*?)<span class="title">(.*?)<\/span> <span class="onlineplaying"><\/span>(.*?)<\/a><\/li>/s', $src, $matches);
			if(isset($matches[3])){
				print count($matches[3]).'<br/>';
				foreach($matches[3] as $v){
					$get_swf = $http->get("http://gamevui.com".$v);
					preg_match_all('/<embed src="(.*?)"(.*?)\/>/s', $get_swf, $row);
					if(isset($row[1][0])){
						$file = $row[1][0];
						$tmp = explode('/',$v);
						$newfile = BASEFOLDER.'games/'.$tmp[1].'.swf';
						if (!copy($file, $newfile)) {
							echo $file.'<br/>';
						}else{
							echo $tmp[1].'.swf'.'<br/>';
						}
					}
				}
			}else{
				print 'Hết';
				exit;
			}
		}
		exit;
	}
}